package com.lm.controller;

import com.lm.domain.User;
import com.lm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liming
 * @create 2017-01-18-13:44
 *
 */
@RestController
public class JsonController {

    @RequestMapping(value = "ajax", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    //@RequestBody 将json对象转成java对象
    //@ResponseBody 表示返回的是json对象
    public @ResponseBody User jsonSource(@RequestBody User user){
        return user;
    }

    @Autowired
    private UserService userService;

    @RequestMapping(path = "users-json")
    public List<User> getAllUsers(){
        return userService.getAll();
    }
}
